$(function () {
    tea(1, 3);
})

//全选
function qx() {
    $("#checkall").click(function () {
        $("input[name='id[]']").each(function () {
            if (this.checked) {
                this.checked = false;
            } else {
                this.checked = true;
            }
        });
    })
}

function tb() {
    $(".table").append("  \t  <tr>\n" +
        "        <td style=\"text-align:left; padding:19px 0;padding-left:20px;\"><input type=\"checkbox\" id=\"checkall\"/>\n" +
        "          全选 </td>\n" +
        "        <td colspan=\"7\" style=\"text-align:left;padding-left:20px;\"><a href=\"javascript:;\" style=\"padding:5px 15px; margin:0 10px;\" class=\"button border-blue icon-edit\" <!--onclick=\"sorts()\"-->> 同意</a><a href=\"javascript:;\" class=\"button border-red icon-trash-o\" style=\"padding:5px 15px;\" <!--onclick=\"DelSelect()\"-->> 否决</a>\n" +
        "         </td>\n" +
        "      </tr>\n" +
        "      <tr>\n" +
        "        <th width=\"100\" style=\"text-align:left; padding-left:20px;\">编号</th>\n" +
        "        <th width=\"10%\">姓名</th>\n" +
        "        <th>教师资格证照片</th>\n" +
        "        <th>身份证号</th>\n" +
        "        <th>性别</th>\n" +
        "        <th>申请年级</th>\n" +
        "        <th>申请类别</th>\n" +
        "       <!-- <th width=\"10%\">申请时间</th>-->\n" +
        "        <th width=\"310\">操作</th>\n" +
        "      </tr>")
}

//教师审核模块
function tea(pageNum, pageSize) {
    $.post("/beyond/selectTeacher", {"pageNum": pageNum, "pageSize": pageSize}, function (data) {
        $.each(data.list, function (i, cha) {
            var sex = cha.gender == 1 ? "女" : "男";
            $(".table").append("<tr>\n" +
                "          <td style=\"text-align:left; padding-left:20px;\"><input type=\"checkbox\" name=\"id[]\" value=\"\" />\n" +
                "          " + (i + 1) + "</td>\n" +
                "          <td>" + cha.name + "</td>\n" +
                "          <td width=\"10%\"><img src='images/" + cha.filename + "' width='100'  height='100' alt=''></td>\n" +
                "          <td>" + cha.number + "</td>\n" +
                "          <td><font color=\"#00CC99\">" + sex + "</font></td>\n" +
                "          <td>" + cha.gradename + "</td>\n" +
                "          <td>" + cha.coursename + "</td>\n" +
                "          <td><div class=\"button-group\"> <a class=\"button border-main\" href=\"javascript:;\" data-id='" + cha.id + "'><span class=\"icon-edit\"></span>查看详情</a></div></td>\n" +
                "        </tr>")
        })
        $(".table").append(" <tr>\n" +
            "                <td colspan=\"9\"><div class=\"pagelist\"></div></td>\n" +
            "            </tr>")

        /*分页*/
        $(".pagelist").empty();
        if (data.pageNum > 1) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="1" >首页</a>')
        }
        if (data.pageNum - 1 >= 1) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="' + (data.pageNum - 1) + '" >上一页</a>')
        }
        $.each(data.navigatepageNums, function (index, fy) {
            if (data.pageNum == fy) {
                $(".pagelist").append(
                    "<a href=\"javascript:void(0)\" style='background-color: skyblue' class=\"curs\" id='" + fy + "'>" + fy + "</a>"
                )
            } else {
                $(".pagelist").append(
                    "<a href=\"javascript:void(0)\" class=\"curs\" id='" + fy + "'>" + fy + "</a>"
                )

            }

        })
        if (data.pageNum < data.pages) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="' + (data.pageNum + 1) + '" >下一页</a>')
        }
        if (data.pageNum < data.pages) {
            $(".pagelist").append('<a href="javascript:void(0)" class="curs"  id="' + data.pages + '" >末页</a>')
        }
        $(".curs").click(function () {
            $(".table").empty();
            tb();
            tea($(this).attr("id"), 3)
            qx();
        })

        $(".button").click(function () {
            var id = $(this).data("id");
            $.post("/beyond/selectByPrimaryKey", {"id": id}, function (data1) {
                $(".panel-head").empty();
                $(".table").empty();
                $(".panel-head").append("<strong class=\"icon-reorder\"> 教师审核详情信息</strong> <a href=\"\" style=\"float:right; display:none;\">添加字段</a>" +
                    "<a href=\"javascript:;\" class='comeback' style='float: right;color: red;font-size: 16px;font-weight: 2px'>返回</a>")
                $.each(data.list, function (i, cha) {
                    console.log(cha)
                    var sex = cha.gender == 1 ? "女" : "男";
                    if (cha.id == id) {
                        $(".table").append("<tr>\n" +
                            "                <th style=\"width:200px;text-align: center\">教师证件照片</th>\n" +
                            "            </tr>\n" +
                            "            <tr>\n" +
                            "                <td rowspan=\"6\"><img src='images/" + cha.identification_photo + "' width='200px' height='190px' alt=''></td>\n" +
                            "            </tr>\n" +
                            "            <tr>\n" +
                            "                <td>编号:" + cha.id + "</td>\n" +
                            "                <td>姓名:" + cha.name + "</td>\n" +
                            "            </tr>\n" +
                            "            <tr>\n" +
                            "                <td>教龄：" + cha.record + "</td>\n" +
                            "                <td>性别:" + sex + "</td>\n" +
                            "            </tr>\n" +
                            "            <tr>\n" +
                            "                <td>电话号码：" + cha.phonenumber + "</td>\n" +
                            "                <td>身份证号:" + cha.number + "</td>\n" +
                            "            </tr>\n" +
                            "            <tr>\n" +
                            "                <td>申请年级:" + cha.gradename + "</td>\n" +
                            "                <td>申请类别:" + cha.coursename + "</td>\n" +
                            "                <!-- <th width=\"10%\">申请时间</th>-->\n" +
                            "            </tr>\n" +
                            "            <tr>\n" +
                            "                <td colspan=\"2\" style='padding-right: 100px'>操作: </br> <div class=\"button-group\"> <a class=\"button border-main\" href=\"javascript:;\" id='ty' data-id='" + cha.id + "'><span class=\"icon-edit\"></span>同意</a> <a class=\"button border-red\" href=\"javascript:;\" id='bty' data-id='" + cha.id + "'><span class=\"icon-trash-o\"></span> 否决</a> </div>\n" +
                            "                </td>\n" +
                            "            </tr>")
                    }
                })
                $(".comeback").click(function () {
                    $(".table").empty();
                    $(".table").append("  \t  <tr>\n" +
                        "        <td style=\"text-align:left; padding:19px 0;padding-left:20px;\"><input type=\"checkbox\" id=\"checkall\"/>\n" +
                        "          全选 </td>\n" +
                        "        <td colspan=\"7\" style=\"text-align:left;padding-left:20px;\"><a href=\"javascript:;\" style=\"padding:5px 15px; margin:0 10px;\" class=\"button border-blue icon-edit\" <!--onclick=\"sorts()\"-->> 同意</a><a href=\"javascript:;\" class=\"button border-red icon-trash-o\" style=\"padding:5px 15px;\" <!--onclick=\"DelSelect()\"-->> 否决</a>\n" +
                        "         </td>\n" +
                        "      </tr>\n" +
                        "      <tr>\n" +
                        "        <th width=\"100\" style=\"text-align:left; padding-left:20px;\">编号</th>\n" +
                        "        <th width=\"10%\">姓名</th>\n" +
                        "        <th>教师资格证照片</th>\n" +
                        "        <th>身份证号</th>\n" +
                        "        <th>性别</th>\n" +
                        "        <th>申请年级</th>\n" +
                        "        <th>申请类别</th>\n" +
                        "       <!-- <th width=\"10%\">申请时间</th>-->\n" +
                        "        <th width=\"310\">操作</th>\n" +
                        "      </tr>")
                    tea(1, 3);
                    qx();
                    $(".comeback").empty();
                })

                /*审核*/
                $("#ty").click(function () {
                    $.post("/beyond/updateTeacherTy", {"id": id}, function (data) {
                        $(".table").empty();
                        tb();
                        tea(1, 3);
                        $(".comeback").empty();
                    })
                })
                $("#bty").click(function () {
                    $.post("/beyond/updateTeacherBty", {"id": id}, function (data) {
                        $(".table").empty();
                        tb();
                        tea(1, 3);
                        $(".comeback").empty();
                    })
                })
            })
        })
        var dd = data.list == 0;
        if (dd) {
            $(".table").empty();
            $(".table").append("<tr>\n" +
                "            <td style='font-size: 16px;color: red'><span style='text-align: center'>暂无数据</span></td>\n" +
                "        </tr>")
        }
    })
}
